<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Tax Calculate</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<style>
    #tax_flow p {
        font-size: large;
    }
</style>
<body>
<div>
    <h2>税额计算</h2>
    <label style="font-size: large">
        到手：
        <input id="input_number" placeholder="Input numbers here" style="font-size: large">
    </label>
    <p style="font-size: large">申报：<span id="shen_bao"></span></p>
</div>
<div id="tax_flow">
    <h2>报税流程</h2>
    <p>1）下载【电子税务局】APP，扫脸完成登录后依次点击【代开增值税发票】-【货物、 服务等一般代开】-【新增代开申请】</p>
    <p>2）【购销双方】的信息，【销售方】为老师本人，点击【添加应税发生地】，选择【天津市-河东区-河东区其他】</p>
    <p>3）【购买方】为【国网天津市电力公司培训中心】，可自动带出具体信息；如果没有，则点击【添加购买方】，选择国网天津市电力公司培训中心（税号系统自动带出）</p>
    <p>4）点击【添加项目信息】，其中【项目编码名称】选择【现代服务-其他现代服务】</p>
    <p>5）【金额】如上计算得出，【税率】为【1%】不要改动，点击【保存】</p>
    <p>6）确认无误后点击【下一步】</p>
    <p>7）提交成功后点击【立即缴款】，付款成功后，下载【完税证明】和【代开发票】</p>
</div>
<script>
    function calculateTax(B3) {
        let result;

        if (B3 <= 800) {
            result = 0;
        } else if (B3 <= 3360) {
            result = 0.2 * ((B3 - 160) / (0.8 * (1 - (0.01 * 0.035))) - 800 - (0.01 * 0.035) * (B3 - 160) / (0.8 * (1 - (0.01 * 0.035))));
        } else if (B3 <= 21000) {
            result = 0.2 * (0.8 - 0.01 * 0.035) * B3 / (0.84 - 0.8 * (0.01 * 0.035));
        } else if (B3 <= 49500) {
            result = (0.3 * (0.8 - 0.01 * 0.035) * (B3 - 2000) / (0.76 - 0.7 * (0.01 * 0.035))) - 2000;
        } else {
            result = 0.4 * (0.8 - (0.01 * 0.035)) * (B3 - 7000) / (0.68 - 0.6 * (0.01 * 0.035)) - 7000;
        }

        // Round the result to 2 decimal places
        return Math.round(result * 100) / 100;
    }

    function calculateTax2(B3) {
        let result;

        if (B3 <= 500) {
            result = 0;
        } else if (B3 <= 800) {
            result = B3 * 0.01 * 0.035;
        } else if (B3 <= 3360) {
            result = 0.01 * 0.035 * (B3 - 160) / (0.8 * (1 - (0.01 * 0.035)));
        } else if (B3 <= 21000) {
            result = 0.01 * 0.035 * B3 / (0.84 - 0.8 * (0.01 * 0.035));
        } else if (B3 <= 49500) {
            result = 0.01 * 0.035 * (B3 - 2000) / (0.76 - 0.7 * (0.01 * 0.035));
        } else {
            result = 0.01 * 0.035 * (B3 - 7000) / (0.68 - 0.6 * (0.01 * 0.035));
        }

        // Round the result to 2 decimal places
        return Math.round(result * 100) / 100;
    }

    function calculateTax3(B3) {
        let result;

        if (B3 <= 500) {
            result = B3;
        } else if (B3 <= 800) {
            result = B3 + B3 * 0.01 * 0.035;
        } else if (B3 <= 3360) {
            result = (B3 - 160) / (0.8 * (1 - (0.01 * 0.035)));
        } else if (B3 <= 21000) {
            result = B3 / (0.84 - 0.8 * (0.01 * 0.035));
        } else if (B3 <= 49500) {
            result = (B3 - 2000) / (0.76 - 0.7 * (0.01 * 0.035));
        } else {
            result = (B3 - 7000) / (0.68 - 0.6 * (0.01 * 0.035));
        }

        // Round the result to 2 decimal places
        return Math.round(result * 100) / 100;
    }

    function calculateTax4(B3, F3) {
        let result;

        if (B3 <= 500) {
            result = 0;
        } else {
            result = F3 * 0.01;
        }

        // Round the result to 2 decimal places
        return Math.round(result * 100) / 100;
    }

    function calculateValue(G3) {
        // 计算结果
        let result = G3 * 0.035;

        // 四舍五入到两位小数
        return Math.round(result * 100) / 100;
    }

    function calculateValue2(B3, J3) {
        let result;

        if (B3 <= 500) {
            result = 0;
        } else {
            result = J3 * 0.01;
        }

        // 四舍五入到两位小数
        return Math.round(result * 100) / 100;
    }

    function calculateValue3(K3) {
        // 计算结果
        let result = K3 * 0.035;

        // 四舍五入到两位小数
        return Math.round(result * 100) / 100;
    }

    function calculateValue4(B3, J3) {
        let result;

        if (B3 <= 500) {
            result = B3;
        } else {
            result = J3 * 1.01;
        }

        // 四舍五入到两位小数
        return Math.round(result * 100) / 100;
    }

    window.onload = () => {
        document.getElementById("input_number").onchange = () => {
            let v = document.getElementById("input_number").value;
            if (v !== "") {
                try {
                    let b3 = parseFloat(v);
                    if (!isNaN(b3)) {
                        console.log("B", b3);
                        let c3 = calculateTax(b3);
                        console.log("C", c3);
                        let d3 = calculateTax2(b3);
                        console.log("D", d3);
                        let e3 = b3 + c3 + d3;
                        console.log("E", e3);
                        let f3 = calculateTax3(b3);
                        console.log("F", f3);
                        let g3 = calculateTax4(b3, f3);
                        console.log("G", g3)
                        let h3 = calculateValue(g3);
                        console.log("H", h3)
                        let i3 = b3 + c3 + g3 + h3 - f3 - g3;
                        console.log("I", i3);
                        let j3 = f3 + i3;
                        console.log("J", j3);
                        let k3 = calculateValue2(b3, j3);
                        console.log("K", k3);
                        let l3 = calculateValue3(k3);
                        console.log("L", l3);
                        let m3 = calculateValue4(b3, j3);
                        console.log("M", m3);
                        document.getElementById("shen_bao").innerText = String(m3);
                    }
                } catch (e) {
                    console.log(e)
                }
            }
        }
    }
</script>
</body>
</html>